package com.quantumoctopus.magiceatball;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.signature.HmacSha1MessageSigner;

public class YelpURLSigner {

	static String CONSUMER_KEY = "WQnfycgeUWLl4-7_TYeAJg";
	static String CONSUMER_SECRET = "9UJxvHd0wL2bO3A__eFdFGgSDhE";
	static String TOKEN = "-k_jghMjvm5rbdkPjQv4eZirKJftLW4i";
	static String TOKEN_SECRET = "IjGIHbjTPOslQBvx9uRbhxhsqSg";

	// returns a signed yelp API URL
	public static String getURLString(String unsignedURLString) {

		OAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY,
				CONSUMER_SECRET);
		consumer.setMessageSigner(new HmacSha1MessageSigner());
		consumer.setTokenWithSecret(TOKEN, TOKEN_SECRET);

		String signedQuery = null;
		try {
			signedQuery = consumer.sign(unsignedURLString);
		} catch (OAuthMessageSignerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (OAuthExpectationFailedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (OAuthCommunicationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return signedQuery;
	}
}
